<?php

!defined('IN_NOVA') && exit('Access Denied!');

class Pages {

	public function start() {
		global $db,$cache,$request;

		$action = $request->get( 'p' );
		$id = $request->id;

		switch( $action ) {
			case 'add':
				$this->show();
				break;
			case 'edit':
				$this->show( 'edit' );
				break;
		}
	}
	private function show( $is_edit = false ) {
		global $db,$request;
		if( $is_edit ) {
			$id = $request->id;
			$result = $db->result( "SELECT * FROM `" . DB_PREFIX . "article` WHERE id={$id} AND isdel=0 AND type=3" );
			if( !$result ) {
				echo 'Page Not Found!';
				return;
			}
		}
?>

<style>
.input_submit { border:1px solid #a3a3a3; background-color: #e7e7e7; padding: 5px; width: 100px; font-weight:bold; }
.admin_content { margin:0px; padding:0px; margin-top:5px; }
.admin_content .input_text { border: 1px solid #c8c8c8; padding: 5px; width: 235px; font-size: 14px; }
.admin_title .tit_right { float: right; font-size: 12px; font-weight:normal; padding-top:2px; }
.admin_content select { border:1px solid #c8c8c8; padding: 5px; width: 245px; font-size: 14px; }
.admin_content .input_radio { margin:5px; }
.admin_title { cursor:pointer; }
</style>

<script type="text/javascript">
	KE.init({
		id : 'page_content',
		resizeMode : 1,
		width : '668px',
		allowFileManager : true,
		newlineTag : 'p'
	});
	var flag_content=false;
</script>

<form method="post" action="index.php?m=page&p=<?php if( $is_edit ) { echo 'saveedit&id=' . $request->id; } else { echo 'saveadd'; }?>" id="ajax_form">

<div style="float:left;width:680px;">

	<div class="admin_panel" onclick="if(!flag_content){flag_content=true;KE.create('page_content');KE.util.focus('page_content');}">
		<div class="admin_title" onclick="javascript:ShowHideDiv('div_page_content')">页面内容<div class="tit_right"></div></div>
		<div class="admin_content">
			<div id="div_page_content">
				<textarea id="page_content" name="page_content" style="width:665px;height:400px;border:1px solid #c8c8c8;"><?php echo $article['content'] ?></textarea>
			</div>
		</div>
	</div>

	<?php if( $action == 'edit' ) { ?>
	<div class="admin_panel">
		<div class="admin_title" onclick="javascript:ShowHideDiv('div_page_upfile')">已有附件<div class="tit_right"></div></div>
		<div class="admin_content">
			<div id="div_page_upfile" style="text-align:left;">
				<?php echo $article['attachment'] ?>
			</div>
		</div>
		<script>
		function to_editor(id, html){
			KE.util.focus(id);
			KE.util.selection(id);
			KE.util.insertHtml(id, html);
		}
		</script>
	</div>
	<?php } ?>

	<div class="admin_panel">
		<div class="admin_title" onclick="javascript:ShowHideDiv('div_page_upload')">上传附件<div class="tit_right"></div></div>
		<div class="admin_content">
			<div id="div_page_upload" style="display:none;">
				<iframe frameborder="0" src="../include/upload.php" width="600" height="110"></iframe>
			</div>
		</div>
	</div>

</div>

<div style="float:right;width:260px;">

	<div class="admin_panel">
		<div class="admin_title" onclick="javascript:ShowHideDiv('div_page_submit')">提交<div class="tit_right"></div></div>
		<div class="admin_content">
			<div id="div_page_submit" style="padding:10px;">
				<input type="submit" onclick="KE.util.setData('page_content');" value=" 提  交 " class="input_submit" />
			</div>
		</div>
	</div>

	<div class="admin_panel">
		<div class="admin_title" onclick="javascript:ShowHideDiv('div_page_title')">标题<div class="tit_right"></div></div>
		<div class="admin_content">
			<div id="div_page_title">
				<input name="page_title" type="text" id="page_title" size="40" class="input_text" value="<?php echo $article['title'] ?>"/>
			</div>
		</div>
	</div>

	<div class="admin_panel">
		<div class="admin_title" onclick="javascript:ShowHideDiv('div_page_alias')">别名<div class="tit_right">允许字母数字与“-”，禁止纯数字</div></div>
		<div class="admin_content">
			<div id="div_page_alias">
				<input name="page_alias" type="text" id="page_alias" size="40" class="input_text" value="<?php echo $article['address'] ?>"/>
			</div>
		</div>
	</div>

	<div class="admin_panel">
		<div class="admin_title" onclick="javascript:ShowHideDiv('div_page_meta')">优化<div class="tit_right">有利于 SEO</div></div>
		<div class="admin_content">
			<div id="div_page_meta" style="display:none;">
				<p style="padding-bottom:5px;text-align:left;">关键字：</p>
				<input name="page_keywords" type="text" id="page_keywords" size="40" class="input_text" value="<?php echo $article['keywords'] ?>" />
				<p style="padding-bottom:5px;padding-top:5px;text-align:left;">描述：</p>
				<textarea name="page_description" type="text" id="page_description" style="padding:5px;width:235px;height:100px;font-size: 14px;border:1px solid #c8c8c8;"><?php echo $article['description'] ?></textarea>
			</div>
		</div>
	</div>

	<div class="admin_panel">
		<div class="admin_title" onclick="javascript:ShowHideDiv('div_page_trackback')">引用通告<div class="tit_right"></div></div>
		<div class="admin_content">
			<div id="div_page_trackback" style="display:none;">
				<input name="page_trackback" type="text" id="page_trackback" size="40" class="input_text" value="<?php echo $article['trackback'] ?>" />
			</div>
		</div>
	</div>

</div>

<div class="fixed"></div>

</form>

<script>
	$(document).ready(function(){
		$('#ajax_form').ajaxForm(function(data){
			showMessage(data);
			$("#admin_loading").css('visibility','hidden');
		});
	});
</script>

<?php
	}

}
?>
